﻿Namespace Buddies
    Public Class Manager
        Private Sub New()
        End Sub

#Region " Events "
        Public Shared Event Updated(ByVal buddy As Entities.Buddy)
        Public Shared Event UpdatedGUI(ByVal buddy As Entities.Buddy)
        Friend Shared Sub OnUpdated(ByVal buddy As Entities.Buddy)
            RaiseEvent Updated(buddy)
            Framework.Threading.Invoke(AddressOf OnUpdated_Callback, buddy)
        End Sub
        Private Shared Sub OnUpdated_Callback(ByVal buddy As Entities.Buddy)
            RaiseEvent UpdatedGUI(buddy)
        End Sub

        Public Shared Event Deleted(ByVal buddy As Entities.Buddy)
        Public Shared Event DeletedGUI(ByVal buddy As Entities.Buddy)
        Friend Shared Sub OnDeleted(ByVal buddy As Entities.Buddy)
            RaiseEvent Deleted(buddy)
            Framework.Threading.Invoke(AddressOf OnDeleted_Callback, buddy)
        End Sub
        Private Shared Sub OnDeleted_Callback(ByVal buddy As Entities.Buddy)
            RaiseEvent DeletedGUI(buddy)
        End Sub
#End Region

        Public Shared Function GetByUniqueId(ByVal uniqueId As String) As Entities.Buddy
            Return Handler.GetByUniqueId(uniqueId)
        End Function
        Public Shared Sub Save(ByVal buddy As Entities.Buddy)
            Handler.Save(buddy)
        End Sub
        Public Shared Sub Delete(ByVal buddy As Entities.Buddy)
            Handler.Delete(buddy)
        End Sub
        Public Shared Function GetById(ByVal id As Integer) As Entities.Buddy
            Return Handler.GetById(id)
        End Function
        Public Shared Function GetAll() As Generic.List(Of Entities.Buddy)
            Return Handler.GetAll
        End Function

        Public Shared Function SelectBuddies(ByVal owner As Form, ByVal options As SelectBuddiesOptions) As Generic.List(Of Entities.Buddy)
            Dim clsView As New FSelectBuddy
            Return clsView.ShowDialog(owner, options)
        End Function

        Public Shared Sub EditBuddy(ByVal owner As System.Windows.Forms.Form, ByVal buddy As Entities.Buddy)
            EditBuddy(owner, buddy, New EditBuddyOptions)
        End Sub

        Public Shared Sub EditBuddy(ByVal owner As System.Windows.Forms.Form, ByVal buddy As Entities.Buddy, ByVal options As EditBuddyOptions)
            Dim clsView As New FEditBuddy
            clsView.Show(owner, buddy, options)
        End Sub

    End Class

    Public Class SelectBuddiesOptions
        Public Caption As String
        Public MultiSelect As Boolean = False
        Public HideBuddyIds As Generic.HashSet(Of Integer)
    End Class
    Public Class EditBuddyOptions
        Public [ReadOnly] As Boolean = False
        Public AllowGroupMembershipEdit As Boolean = True
    End Class

End Namespace